
//验证登陆
function checkLoginForm(form){
	for(i=0;i<form.length-1;i++){
		if(form.elements[i].value==""){
			alert(form.elements[i].title);
			form.elements[i].focus();
			return false;
		}
	}
	// alert(form.elements[0]);
}

// 验证注册
function checkemail(email){
	 var str=email;
	 var Expression=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; 
	 var objExp=new RegExp(Expression);
	 if(objExp.test(str)==true){
	  return true;
	 }else{
	  return false;
	 }
	}

function checkEditForm(){
	var form=document.getElementById("editForm");
	var password=document.getElementById("password");
	var repwd=document.getElementById("repeatedPassword");
	var email=document.getElementById("email");
	for(i=0;i<form.length;i++){
		if(form.elements[i].value==""){
			alert(form.elements[i].title);
			form.elements[i].focus();
			return false;
		}
	}
	
	 if(password.value!= repwd.value){
	      alert("您输入的两次密码不一致!");
	      password.value="";
	      repwd.value="";
	      password.focus();
	      return false;
	   }
	  // 检查邮件格式
	  if(!checkemail(email.value)){
		   alert("邮箱的格式不正确!");
		   email.focus();
		   return false;
	  }
}
function checkRegForm(){   
  
   var form=document.getElementById("regForm");
   var username=document.getElementById("username");
   var password=document.getElementById("password");
   var repwd=document.getElementById("repeatedPassword");
   var email=document.getElementById("email");
   
   for(i=0;i<form.length;i++){
		if(form.elements[i].value==""){
			alert(form.elements[i].title);
			form.elements[i].focus();
			return false;
		}
	}
   // 长度限制
   if(username.value.length <2 || username.value.length > 16){
	   alert("长度不符合要求");
	   username.value="";
	   username.focus();
	   return false;
   }
   
   if(password.value!= repwd.value){
	      alert("您输入的两次密码不一致!");
	      password.value="";
	      repwd.value="";
	      password.focus();
	      return false;
	   }
   // 检查邮件格式
   if(!checkemail(email.value)){
	   alert("邮箱的格式不正确!");
	   email.focus();
	   return false;
   }
   
   // form.submit();
}

function checkModifyForm(){
	 var form=document.getElementById("modfiyForm");
	 var password=document.getElementById("password");
	 var repwd=document.getElementById("rePassword");
	   
	 for(i=0;i<form.length;i++){
		if(form.elements[i].value==""){
			alert(form.elements[i].title);
			form.elements[i].focus();
			return false;
		}
	}
	   
   if(password.value!=repwd.value){
	      alert("您输入的两次密码不一致!");
	      password.value="";
	      repwd.value="";
	      password.focus();
	      return false;
   }  
}



// 验证问题
function checkQuestionForm(){
	var form = document.getElementById("insertAndUpdateForm");
	var content = document.getElementById("content");
	var resultA = document.getElementById("resultA")
	var resultB = document.getElementById("resultB")
	var resultC = document.getElementById("resultC")
	var resultD = document.getElementById("resultD")
	
	
	if(content.value == ""){
		alert("请输入题目标题");
		content.focus();
		return false;
	}
	
	if(content.value.length > 30){
		alert("长度不符合要求");
		content.value = "";
		content.focus();
		return false;
	}
	if(resultA.value == ""){
		alert("请输入选项A");
		resultA.focus();
		return false;
	}
	
	if(resultB.value == ""){
		alert("请输入选项B");
		resultB.focus();
		return false;
	}
	if(resultC.value == ""){
		alert("请输入选项C");
		resultC.focus();
		return false;
	}
	if(resultD.value == ""){
		alert("请输入选项D");
		resultD.focus();
		return false;
	}
}

function del() {
	var msg = "您真的确定要删除吗？\n\n请确认!";
	if (confirm(msg)==true){
		return true;
	}else{
		return false;
	}
}

function phaseDel() {
	var msg = "活动对应的奖品数据也会一并删除!\n\n您真的确定要删除吗？";
	if (confirm(msg)==true){
		return true;
	}else{
		return false;
	}
}

// prize
function checkPrizeForm(){
	var form = document.getElementById("prizeForm");
	var prizeName = document.getElementById("prizeName");
	var prizePrice = document.getElementById("prizePrice");
	var phaseId	= document.getElementById("phaseId");
	
	if(prizeName.value == ""){
		alert("请输入奖品名称");
		prizeName.focus();
		return false;
	}
	
	if(prizeName.value.length > 30){
		alert("长度不符合要求");
		prizeName.value = "";
		prizeName.focus();
		return false;
	}
	if(phaseId.value == ""){
		alert("请选择活动");
		phaseId.focus();
		return false;
	}
	
	if(prizePrice.value!=""){
		if(!IsNum(prizePrice.value,"0") || prizePrice.value.length >20){
			alert("非法数字,请重新输入");
			prizePrice.value == "";
			prizePrice.focus();
			return false;
		}
	}
	
}

// 判断是否是正整数
function IsNum(s,flag)
{
	
    if(s!=null){
        var exp;
        if(flag == "0"){
    		// 整数和小数
        	exp = /^\-?[0-9]+\.?[0-9]{0,9}$/; 
    	}else{
    		// 正整数
    		exp = /^[1-9]\d*$/;
    	}
        if(!exp.test(s)){
        	return false;
        }else{
        	return true;
        }
    }
    return false;
}



// phase
function checkphaseForm(){
	var phaseName = document.getElementById("phaseName");
	var gmtstart = document.getElementById("gmtstart");
	var gmtend = document.getElementById("gmtend");
	var exceptParticiants= document.getElementById("exceptParticiants");
	
	// 不能为空而且长度不能大于30
	if(phaseName.value == ""){
		alert(phaseName.title);
		phaseName.focus();
		return false;
	}
	
	if(phaseName.value.length < 2 || phaseName.value.length > 30){
		alert("长度不符合要求");
		phaseName.value="";
		phaseName.focus();
		return false;
	}
	
	if(gmtstart.value == ""){
		alert("开始时间不能为空");
		gmtstart.focus();
		return false;
	}
	
	if(gmtend.value==""){
		alert("结束时间不能为空");
		gmtend.focus();
		return false;
	}
	
	// 检查参与人数
	if(exceptParticiants.value==""){
		alert("请输入参与人数");
		exceptParticiants.focus();
		return false;
	}
	
	if(!IsNum(exceptParticiants.value,"1")){
		alert("非法数字,请重新输入");
		exceptParticiants.value= "";
		exceptParticiants.focus();
		return false;
	}
	
	if(IsNum(exceptParticiants.value,"1")){
		if(exceptParticiants.value<100){
			alert("输入的数字小于100");
			exceptParticiants.value= "";
			exceptParticiants.focus();
			return false;
		}
	}
}

function changePageIndex(){
	// alert("提交");
	var form = document.getElementById("phaseForm");
	form.action='/lottery/admin/prizeQuota.do?action=prizeDisplay';
	form.submit();
}

function changeStat(){
	// alert("提交");
	var form = document.getElementById("statForm");
	form.action='/lottery/admin/statistic.do?action=diplayImage';
	form.submit();
}

function checkPhase(){
	var form = document.getElementById("insertStatForm");
	var phaseId=document.getElementById("phaseId");
	if(phaseId.value==""){
		alert("请选择活动");
		phaseId.focus();
		return false;
	}
}
function checkQuotaForm(){
	var form = document.getElementById("quotaForm");
	var count = document.getElementById("count");
	
	// alert(count.value);
	for(i=0;i<count.value;i++){
	 
	 var prizeAmount = document.getElementById("prizeAmount"+i);
	 var avaliableCount = document.getElementById("avaliableCount"+i);
	 
	 if(prizeAmount.value==""){
		 alert(prizeAmount.title);
		 prizeAmount.focus();
		 return false;
	 }
	 
	 if(avaliableCount.value==""){
		 alert(avaliableCount.title);
		 avaliableCount.focus();
		 return false;
	 }
	 
	 if(!IsNum(prizeAmount.value,"1")){
		 alert("非法数字,请重新输入");
		 prizeAmount.value= "";
		 prizeAmount.focus();
		 return false;
	 }
	 if(!IsNum(avaliableCount.value,"1")){
		 alert("非法数字,请重新输入");
		 avaliableCount.value= "";
		 avaliableCount.focus();
		 return false;
	 }
	 }
}